package face.pay.common.order.impl;

import face.pay.common.order.IOrderAnalysisService;
import face.pay.dao.OrderAnalysisDao;
import face.pay.entity.UserInfo;
import face.pay.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class OrderAnalysisServiceImpl implements IOrderAnalysisService {


    @Autowired
    OrderAnalysisDao orderAnalysisDao;

    @Override
    public Map volumeTrade(String queryDay, UserInfo loginUser) {

        Map datMap =  new HashMap();

        Integer userId = loginUser.getId();


        /**
         * x轴数组
         */
        List xlist = new ArrayList();


        /**
         * y轴数组
         */
        List ylist = new ArrayList();


        String endDay =      queryDay;

        Date endDate  =      DateUtil.dateParse(queryDay,"yyyy-MM-dd");

        if(endDate==null){
            endDate =  new Date();
            endDay = DateUtil.dateFormat(new Date(),"yyyy-MM-dd");
        }

        Date startDate    =      DateUtil.addDay(endDate,-7);

        String startDay   =      DateUtil.dateFormat(startDate,"yyyy-MM-dd");

        List<Map> list=  orderAnalysisDao.volumeTrade(startDay,endDay,userId);

        for(Map data :list){

            String data_day = data.get("data_day").toString();
            String money = data.get("money").toString();
            xlist.add(data_day);
            ylist.add(money);

        }

        datMap.put("xlist",xlist.toArray());
        datMap.put("ylist",ylist.toArray());
        return datMap;
    }
}
